LevelHandler.AddLevel(Level1);
LevelHandler.AddLevel(Level2);

LevelHandler.setLevel(1);
var CurrentLevel = LevelHandler.getLevelvar();


//Example of a monster getting the next location from the starting
var origin = CurrentLevel.getStart();
var monster = {
    x: origin.x,
    y: origin.y,
    target: origin.getNext(origin),
	prevTarget: origin,
    drawID: indexhero,
	getNextTar:function() {
		var temp = this.target.getNext(this.prevTarget);
		this.prevTarget = this.target;
		this.target = temp;
	}
};

//Setup drawlist
var DrawArray = [];

//This was removed because there is no easy way to change out the values in the drawarray
// CurrentLevel.MapArray can be drawn directly and will update when the level changes
//To Add an array
//DrawArray = DrawArray.concat(CurrentLevel.MapArray);

//To Add a single value
DrawArray.push(monster);



function reset() {
	Start = CurrentLevel.getStart();
    monster.x = Start.x;
    monster.y = Start.y;
    monster.target = Start;
	monster.prevTarget = Start;
}
function NextLevel() {
	//Moves to the level after the current one if it exists
	if(LevelHandler.setLevel(LevelHandler.getLevel()+1) != false)
		CurrentLevel = LevelHandler.getLevelvar();
		
	//Resets the monster to the beginning
	reset();
	
}

function update() {
	if (monster.x == monster.target.x && monster.y == monster.target.y) {
		if (monster.target.type == "End")
			//Temporarily changed so that I can test switching levels
			//NextLevel();
			reset();
		monster.getNextTar();
	}

    if (monster.x < monster.target.x)
        monster.x += 1;
    else if (monster.x > monster.target.x)
        monster.x -= 1;

    if (monster.y < monster.target.y)
        monster.y += 1;
    else if (monster.y > monster.target.y)
        monster.y -= 1;
}


var IE = document.all ? true : false


function main() {
	// CurrentLevel.MapArray can be drawn directly and will update when the level changes
	// The map must be drawn first so that the enemy appears on top
	drawList.drawAll(CurrentLevel.MapArray);
    drawList.drawAll(DrawArray);
	

    if (!IE) document.captureEvents(Event.MOUSEMOVE)
    document.onmousemove = getMouseXY;
    //context.fillText("Hello, world!", 10, 10);

    update();
    ctx.fillStyle = "rgb(250, 250, 250)";
    ctx.font = "18px Helvetica";
    ctx.textAlign = "left";
    ctx.textBaseline = "top";
    ctx.fillText("(" + mouseX + "|" + mouseY + ")", 0, 0);
}


setInterval(main, 1);
